package com.yuanmei.model;

import com.yuanmei.common.Utils;

import java.util.Map;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;

public class TickQuote extends RealmObject implements Comparable<TickQuote> {
    @PrimaryKey
    private int tick;
    private float amount, volume, price;
    private String type;


    public TickQuote() {
        super();
    }

    public TickQuote(
            String tick, float amount, float volume,
            float price, String type) {
        this.tick = Utils.parseTickFromString(tick);
        this.amount = amount;
        this.volume = volume * 100;
        this.price = price;
        this.type = type;
    }

    public TickQuote(String minuteTick, float volume, float price) {
        int tick = Integer.valueOf(minuteTick);
        this.tick = tick * 100;
        this.volume = volume;
        this.amount = volume * price;
        this.price = price;
        this.type = "--";
    }

    public TickQuote(String[] inValues, Map<String, Integer> fieldsMap) {
        this.tick = Utils.parseTickFromString(inValues[fieldsMap.get("tick")]);
        this.price = Utils.safeToFloat(inValues[fieldsMap.get("price")]);
        this.volume = Utils.safeToFloat(inValues[fieldsMap.get("volume")]) * 100;
        this.amount = Utils.safeToFloat(inValues[fieldsMap.get("amount")]);
        this.type = inValues[fieldsMap.get("type")];
    }

    public TickQuote(
            int tick, int volume,
            int price, String type) {
        this.tick = tick;
        this.volume = volume * 100;
        this.price = (float)price / 100;
        this.amount = this.volume * this.price;
        this.type = type;
    }

    public int getTick() {
        return tick;
    }

    public void setTick(int tick) {
        this.tick = tick;
    }

    public float getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }


    public float getVolume() {
        return volume;
    }

    public void setVolume(int volume) {
        this.volume = volume;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public int hashCode() {
        return tick;
    }

    @Override
    public int compareTo(TickQuote other) {
//        if (this.hashCode() < other.hashCode())
//            return -1;
//        else if (this.hashCode() > other.hashCode())
//            return 1;
//        else
//            return 0;
        return Integer.compare(this.hashCode(), other.hashCode());
    }
}


